package com.cyy.vue.controller;

import com.cyy.vue.MyResult;
import com.cyy.vue.entry.CloudTest;
import com.cyy.vue.entry.User;
import com.cyy.vue.service.TestService;
import com.cyy.vue.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class TestComtroller {


    @Autowired
    private TestService testService;

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    @ResponseBody
    public String getHello() {
        return "hello";
    }

    @RequestMapping("/list")
    public String getList(ModelMap map){
        String sql = "select * from cloud_test";
        List<CloudTest> list = testService.findAll();
        map.addAttribute("list",list);
        return "user";
    }

    @GetMapping("/findAll")
    @ResponseBody
    public List<CloudTest> findAll(){
        List<CloudTest> list = testService.findAll();
        return list;
    }

    @RequestMapping("/login")
    @ResponseBody
    public MyResult login(@RequestBody User user){
        return userService.login(user);
    }
}
